/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Controller;

import com.DAO.AcervoDAO;
import com.thoughtworks.xstream.XStream;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;

/**
 *
 * @author Fellipe
 */
@WebService(serviceName = "Acervo")
public class Acervo {

    private AcervoDAO a = new AcervoDAO();
    private XStream xstream = new XStream();

//Serviços Web    
    @WebMethod(operationName = "read")
    public String readAcervo(int chaveAcervo) {
        
        return toXMLAcervoList(a.read(chaveAcervo));
        
    }
    
    @WebMethod(operationName = "readNomes")
    public String readNomesAcervo() {
        
        return toXMLAcervo(a.readNomes());
        
    }

    @WebMethod(operationName = "create")
    public void createAcervo(String xml) {
        
        a.create(fromXMLAcervo(xml));
        
    }

    @WebMethod(operationName = "update")
    public void updateAcervo(String xml) {
        
        a.update(fromXMLAcervo(xml));
        
    }

    @WebMethod(operationName = "delete")
    public void deleteAcervo(int chaveAcervo) {
        
        a.delete(chaveAcervo);
        
    }
    
    @WebMethod(operationName = "buscaNome")
    public String buscaNomeAcervo(String busca) {
        
        return toXMLAcervo(a.buscaNome(busca));
        
    }

//Funções XML    
    private String toXMLAcervoList(com.Model.Acervo acervo) {
        
        return xstream.toXML(acervo);
        
    }
    
    private String toXMLAcervo(List<com.Model.Acervo> lista) {
        
        return xstream.toXML(lista);
        
    }

    private com.Model.Acervo fromXMLAcervo(String xml) {
        
        return (com.Model.Acervo) xstream.fromXML(xml);
        
    }
}
